package datastructure.set;

import datastructure.set.set.ListSet;
import datastructure.set.set.Set;
import datastructure.set.set.TreeSet;
import utils.Times;
import utils.file.FileInfo;
import utils.file.Files;

/**
 * @Description: 测试ListSet和TreeSet的性能
 * @Author Ammar
 * @Create 2023/4/19 23:28
 */
public class Test {
    public static void main(String[] args) {
//        testSet();

    }


    static void testSet(Set<String> set, String[] words) {
        for (int i = 0; i < words.length; i++) {
            set.add(words[i]);
        }
        for (int i = 0; i < words.length; i++) {
            set.contains(words[i]);
        }
        for (int i = 0; i < words.length; i++) {
            set.remove(words[i]);
        }
    }

    static void testSet() {
        FileInfo fileInfo = Files.read("/Users/Ammar/Documents/ALIYUN/blogArticles",
                new String[]{"md"});
        System.out.println("文件数量：" + fileInfo.getFiles());
        System.out.println("文本行数：" + fileInfo.getLines());
        String[] words = fileInfo.words();
        System.out.println("单词数量：" + words.length);

        Times.test("ListSet", new Times.Task() {
            @Override
            public void execute() {
                testSet(new ListSet<>(), words);
            }
        });
        Times.test("TreeSet", new Times.Task() {
            @Override
            public void execute() {
                testSet(new TreeSet<>(), words);
            }
        });
    }
}
